#!/bin/bash
# curl  -s http://wuyou.run/services/install-py3.9.sh|bash


if [ -f /usr/bin/python3 ];then
    echo "检测到python3已安装"
else
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel python-devel \
 libffi-devel  tk-devel -y
if [ ! -f Python-3.* ];then
    wget -c  https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tar.xz
    if [ $? != 0 ]; then
            echo "下载失败 !!!"
            exit 1
    fi	
fi

tar xf Python*xz
cd Python-3.*
./configure --prefix=/usr/local
make && make  altinstall
# altinstall在安装时会区分已存在的版本

rm /usr/bin/python3.9 /usr/bin/python3 -f
ln -s /usr/local/bin/python3.9 /usr/bin/
ln -s /usr/local/bin/python3.9 /usr/bin/python3
cd ..
fi